<?php

namespace App\Http\Controllers\Admin\RunTest;

use App\Exceptions\LogicException;
use App\Http\Controllers\Controller;
use App\Models\TestApi\TestModule;
use App\Utils\QueryUtil;
use App\Utils\ResUtil;

class TestModuleController extends Controller
{
    public function list()
    {
        $request = request()->all();
        $query = TestModule::where(function($query) use($request) {
            QueryUtil::selectBuild($query, $request, [
                ['test_report_uid', '='],
                ['cate_name', 'like', 'cate_name'],
                ['project_name', 'like', 'project_name'],
                ['product_name', 'like', 'product_name'],
                ['f_module_name', 'like', 'f_module_name'],
                ['s_module_name', 'like', 's_module_name'],
                ['f_module_name', 'like', 'f_module_name'],
                ['s_module_id', '='],
                ['status', '='],
                ['id', '='],
            ]);
        });

        $total = $query->count();
        $models = QueryUtil::queryList($query);
        $list = [];
        foreach($models as $i => $v) {
            $list[$i] = $v?->label()?->toArray();
        }
        list($status_maps, $hasMore) = [
            TestModule::$status_maps, QueryUtil::hasMore(sizeof($list))
        ];
        return $this->ok(compact('list', 'total', 'hasMore', 'status_maps'));
    }
}
